package com.zhuoshi.controller;

import java.util.List;
import java.util.UUID;

import javax.xml.stream.events.Namespace;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhuoshi.bean.WdHtBuild;
import com.zhuoshi.bean.WdHtProject;
import com.zhuoshi.service.WdHtBuildService;
import com.zhuoshi.service.WdHtProjectService;
import com.zhuoshi.serviceImpl.WdHtBuildServiceImpl;

@Controller
public class WdHtBuildController {

	@Autowired
	private WdHtBuildService WdHtBuildServiceImpl;

	/**
	 * 鏌ヨ鍏ㄩ儴鐨勬ゼ鏍�
	 */
	@RequestMapping("/build/list")
	public String list(Model model) {
		List<WdHtBuild> list = WdHtBuildServiceImpl.getAll();
		model.addAttribute("list", list);
		return "build_list";
	}

	/**
	 * 璺宠浆鍒版坊鍔犵晫闈�
	 */
	@RequestMapping("/build/toAdd")
	public String toAdd(Model model) {
		List<WdHtProject> list = WdHtBuildServiceImpl.getAllProject();
		model.addAttribute("list", list);
		return "build_add";
	}
	 /**
	 * 娣诲姞涓�涓殑鍔熻兘
	 */
	 @RequestMapping("/build/add")
	 public String add(WdHtBuild wdHtBuild) {
	 //璁剧疆uuid
	 wdHtBuild.setBuildId((UUID.randomUUID().toString()));
	 WdHtBuildServiceImpl.add(wdHtBuild);
	 return "redirect:/build/list.do";
	 }
	 /**
	 * 鍒犻櫎涓�涓殑鍔熻兘
	 */
	 @RequestMapping("/build/del")
	 public String del(String projectId)
	 {
	 //鍒犻櫎鐨剆ervice鏂规硶
	  WdHtBuildServiceImpl.del(projectId);
	  return "redirect:/build/list.do";
	 }
	
	 /** 
	 * 鏌ヨ涓�涓殑鍔熻兘
	 */
	 @RequestMapping("/build/toupdate")
	 public String toUp(String buildId,Model model)
	 {
	 //鏌ヨ涓�涓�
	  WdHtBuild bean = WdHtBuildServiceImpl.selectOne(buildId);
	  model.addAttribute("bean",bean);
	  return "build_update";
	 }
	
	 /**
	 * 鏇存柊涓�涓殑鍔熻兘
	 */
	 @RequestMapping("/build/update")
	 public String toUp(WdHtBuild wdHtBuild)
	 {
	 //鏇存柊涓�涓�
		 WdHtBuildServiceImpl.upOne(wdHtBuild);
	 return "redirect:/build/list.do";
	 }
}
